#include "Json.h"
#include "CurlBase.h"
#include "DThread.h"
#include "MFile.h"

void ShowFileList(gpointer data,gpointer user_data){
    FileModel *model = (FileModel *)data;
    g_printf("User Data: %d\n",model->id);
}

int main(int argc,char * argv[]){
//    char *JsonValue = "{\"code\":1,\"msg\":\"请求成功\",\"data\":"
//    "{\"FileList\":[{"
//            "\"id\":62,"
//            "\"name\":\"2a56efaa-cb65-4839-8915-d9483e016c92\","
//            "\"filename\":\"omnetpp.pdf\","
//            "\"url\":\"http://localhost:8080/file/get/62/\","
//            "\"uploader_name\":\"tang\",\"suffixname\":\".pdf\"}],"
//            "\"ColumnList\":["
//            "\"id\",\"name\",\"suffixname\",\"filename\",\"url\",\"uploader_name\""
//    "]}}";

    char *JsonValue = HttpJsonGet("http://localhost:8080/file/jlist/");
//    g_printf("%s\n",JsonValue);
    JsonObject *object = JsonBase(JsonValue);
    const gint code = json_object_get_int_member(object,"code");
    if(code == CODE_SUCCESS){
        GPtrArray *FileList = FileColumnJsonDecode(object);
        g_ptr_array_foreach(FileList,(GFunc)ShowFileList,NULL);
        GPtrArray *FileListArray = FileColumnArray(object);
        int array_length = g_ptr_array_index(FileListArray,0);
        int mos = 1;
        for(;mos<(array_length+1);mos++)
            g_print("%s\n",(gchar*)g_ptr_array_index(FileListArray,mos));
    }else{
        printf("** Erorr For %s\n",Error(json_object_get_string_member(object,"msg")));
    }
    g_message("Code: %d" , code);
    return (0);
}
